package com.mall.shopping.services;

import com.mall.shopping.IHomeService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dal.persistence.PanelMapper;
import com.mall.shopping.dto.HomePageResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author qugr
 * @create 2020-07-11 11:38
 */
@Slf4j
@Component
@Service
public class HomePageServiceImpl implements IHomeService {

    @Autowired
    PanelMapper panelMapper;

    @Override
    public HomePageResponse homepage() {

        HomePageResponse response = new HomePageResponse();
        response.setPanelContentItemDtos(panelMapper.selectHomePagePanel());

        if (response.getPanelContentItemDtos().isEmpty()) {
            response.setCode(ShoppingRetCode.DB_EXCEPTION.getCode());
            response.setMsg(ShoppingRetCode.DB_EXCEPTION.getMessage());
            return response;
        }

        response.setCode(ShoppingRetCode.SUCCESS.getCode());
        response.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        return response;
    }
}
